package org.example.Soution001;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class PermutationsPro {
    public static void main(String[] args) {
        PermutationsPro p = new PermutationsPro();
        int[] nums={};
        System.out.println(p.permute(nums));
    }

    public List<List<Integer>> permute(int[] nums) {
        //结果列表
        List<List<Integer>> res = new ArrayList<List<Integer>>();
        //当前排序
        List<Integer> list=new ArrayList<>();
        for(int num : nums) {
            list.add(num);
        }
        int len=nums.length;
        permuteCore(res,list,len,0);
        return res;
    }

    public void permuteCore(List<List<Integer>> res,List<Integer> list,int len,int pos) {
        if(pos==len) {
            res.add(new ArrayList<>(list));
        }
        for(int i=pos;i<len;i++) {
            //交换确定这一位的元素
            Collections.swap(list,i,pos);
            permuteCore(res,list,len,pos+1);
            Collections.swap(list,i,pos);
        }
    }
}
